/*
diy实体类
描述diy的属性和对应的map方法
 */

class Diy {
  int _diyId; //diy项目的id
  String _diyName; //diy活动名称
  String _diyPlace; //diy活动地点
  String _diyDate; //diy活动时间
  int _diyNums;
  int _diySinglePrice;
  int _diyPrice; //diy活动总价格
  int _diyItemCost; //diy活动物料
  int _diyLaborCost; //diy活动人力
  int _diyProfit; //diy活动利润
  String _diyLeader; //diy金主
  String _diyImagePath;

  Diy(
      this._diyName,
      this._diyPlace,
      this._diyDate,
      this._diyLeader,
      // this._diySinglePrice,
      // this._diyNums,
      this._diyPrice,
      this._diyItemCost,
      this._diyLaborCost,
      this._diyProfit,
      this._diyImagePath);

  String get name => _diyName; //获取diy活动名称
  String get place => _diyPlace; //获取diy活动地点
  String get date => _diyDate; //获取活动时间
  int get singlePrice => _diySinglePrice; //获取活动单价
  int get nums => _diyNums; //获取活动份数
  int get price => _diyPrice; //获取diy活动价格
  int get itemCost => _diyItemCost; //获取diy物料价格
  int get laborCost => _diyLaborCost; //获取diy人力价格
  int get profit => _diyProfit; //获取diy活动利润
  int get id => _diyId; //获取diyID
  String get leader => _diyLeader; //获取金主名字
  String get path => _diyImagePath;

  //将diy活动属性和数据库表字段形成映射关系
  Map<String, dynamic> toMap() {
    var map = <String, dynamic>{
      "Name": _diyName,
      "place": _diyPlace,
      "price": _diyPrice,
      "itemCost": _diyItemCost,
      "laborCost": _diyLaborCost,
      "profit": _diyProfit,
      "leader": _diyLeader,
      "date": _diyDate,
      "image": _diyImagePath,
      "nums": _diyNums,
      "singlePrice": _diySinglePrice
    };
    if (_diyId != null) {
      map['id'] = _diyId;
    }
    return map;
  }

  //根据传入的map，将对应的值赋给diy的各个属性
  Diy.fromMap(Map<String, dynamic> map) {
    _diyId = map['id'];
    _diyName = map['name'];
    _diyPlace = map['place'];
    _diyPrice = map['price'];
    _diyItemCost = map['itemCost'];
    _diyLaborCost = map['laborCost'];
    _diyProfit = map['profit'];
    _diyLeader = map["leader"];
    _diyDate = map["date"];
    _diyImagePath = map["image"];
    _diyNums = map["nums"];
    _diySinglePrice = map["singlePrice"];
  }
}

//  Diy.map(dynamic obj) {
//    _diyId = obj["id"];
//    _diyName = obj["name"];
//    _diyPlace = obj["place"];
//    _diyPriceTotal = obj["price"];
//    _diyLeader = obj["leader"];
//    _diyDate = obj['date'];
//  }
